<?php

function smarty_function_html_db_table($params, &$smarty){
	$table_attr = 'border="1"';
	$tr_attr = '';
	$td_attr = '';
	$trailpad = '&nbsp;';
	$th_loop = 0;


	if (!isset($params['loop'])){
	    $smarty->trigger_error("html_table: missing 'loop' parameter");
	    return;
	}

	foreach ($params as $_key=>$_value){
		$$_key = $_value;
	}

	$output = "<table $table_attr>\n";

	if ($th_loop != 0){
		$output.="<tr>\n";
		foreach($th_loop as $tt){
			$output.="<th>$tt</th>\n";
		}
		$output.="</tr>\n";
	}

	foreach($loop as $row){
		$output.="	<tr $tr_attr>\n";
	 	foreach($row as $value){
			$output.="	<td $td_attr>\n";
			if (is_null($value)){
				$output.= "		&nbsp\n";
			}else{
		 		$output.= "		".$value."\n";
		 	}
			$output.="	</td>\n";
		}
		$output.="	</tr>\n";
	}
	$output.= "</table>\n";


	return $output;
}

?>
